package OOP.Homeworks.Homework01;
/*
1.定义一个Person类{name，age，job}，初始化Person对象数组，
 有3个person对象，并按照age从大到小进行排序，提示，使用冒泡排序
 */
public class Test {
    public static void main(String[] args) {
        //创建三个实例化对象
        Person person[] = new Person[3];
        person[0] = new Person("小明", 10, "学生");
        person[1] = new Person("小红", 23, "教师");
        person[2] = new Person("小亮", 12, "学生");
        Person temp;

        //根据年龄冒泡排序
        for (int i = 0; i < person.length - 1; i++) {
            for (int j = 0; j < person.length - i - 1; j++) {
                if (person[j].getAge() < person[j + 1].getAge()) {
                    temp = person[j];
                    person[j] = person[j + 1];
                    person[j + 1] = temp;
                }
            }
        }

        //打印信息
        for (int i = 0; i < person.length; i++) {
            System.out.println(person[i].getMessage());
        }
    }
}
